using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Entities;
using Dao;
namespace Doctors_WebForum
{
    public partial class AdminMasterPage : System.Web.UI.MasterPage
    {
        
        private string id;
        protected void Page_Load(object sender, EventArgs e)
        {
            // request parameter of string view 
            string view = Request["view"];
            if (Session["user"] == null)
            {
                Response.Redirect("Login.aspx", true);
            }
            else
            {
                User user = new User();
                user = Session["user"] as User;
                UserData userData = new UserData();
                user = userData.GetByName(user.UserName);
                if (user == null)
                {
                    Response.Redirect("Login.aspx", true);
                }
                else
                {
                    lblName.Text = user.UserName;
                    id = user.UserID.ToString();
                    lblLastLogin.Text = user.LastLogin.ToString();
                }
            }

        }

        protected void lbSingOut_Click(object sender, EventArgs e)
        {
            if (!id.Equals(""))
            {
                UserData userData = new UserData();
                if (userData.UpdateLastLogin(DateTime.Now, Utility.ToInt(id)) == true)
                {
                    FormsAuthentication.SignOut();
                    HttpContext.Current.Session.Clear();
                    HttpContext.Current.Session.Abandon();
                    Response.Redirect("Login.aspx");
                }
                else
                {
                    FormsAuthentication.SignOut();
                    HttpContext.Current.Session.Clear();
                    HttpContext.Current.Session.Abandon();
                    Response.Redirect("Login.aspx");
                }
            }
            else
            {
                FormsAuthentication.SignOut();
                HttpContext.Current.Session.Clear();
                HttpContext.Current.Session.Abandon();
                Response.Redirect("Login.aspx");
            }

        }
    }
}
